/*
package com.jymj.controller;

import com.jymj.entity.zjd.ZjdFileEntity;
import com.jymj.entity.zjd.ZjdLzEntity;
import com.jymj.service.ZjdFileService;
import com.jymj.service.ZjdLzService;
import com.jymj.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;

*/
/**
 * Created by ljj on 2019/10/14.
 * 宅基地流转
 *//*

@RestController
@RequestMapping("ZjdLz")
public class ZjdLzController extends AbstractController {
    @Autowired
    private ZjdLzService zjdLzService;
    @Autowired
    private ZjdFileService zjdFileService;

    private final String SAVE_PATH = "zjdlzfile";
    //创建一个springmvc上传文件解析器

    */
/**
     * 宅基地流转 列表
     *//*

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public R list(@RequestBody Map<String, Object> params){
        String xzqmc = null;
        String point = null;
        Integer sptype = null;
        Integer limit = null;
        Integer page = null;
        ArrayList list = null;
        if (params.get("xzqmc") != null && params.get("xzqmc") != null){
            xzqmc = params.get("xzqmc").toString();
        }
        if (params.get("sptype") != null && params.get("sptype") != null){
            sptype = Integer.parseInt(params.get("sptype").toString());
        }
        if (params.get("limit") != null && params.get("limit") != null){
            limit = Integer.parseInt(params.get("limit").toString());
        }
        if (params.get("page") != null && params.get("page") != null){
            page = Integer.parseInt(params.get("page").toString());
        }
        if (params.get("point") != null && params.get("point") != null){
            point =  params.get("point").toString();
        }
        if(params.containsKey("codeList") && params.get("codeList") != null){
            String codes  = params.get("codeList").toString();
            String i = codes.substring(1,codes.length()-1);
            String str= i.replace("\"", "");
            list = new ArrayList(Arrays.asList(str.split(",")));
        }
        List<ZjdLzEntity> zjdLzList = null;
        int total = 0;
        if (params != null && page != null && limit != null){
            Query query = new Query(params);
            query.put("xzqmc", xzqmc);
            query.put("sptype",sptype);
            query.put("point",point);
            query.put("codeList",list);
            zjdLzList = zjdLzService.queryList(query);
            total = zjdLzService.queryTotal(query);
        }else {
            zjdLzList = zjdLzService.queryList(params);
            total = zjdLzService.queryTotal(params);
        }
        if (limit == null){
            limit = 0;
        }
        if (page == null){
            page = 0;
        }
        PageUtils pageUtil = new PageUtils(zjdLzList, total, limit, page);
        return R.ok().put("data", pageUtil);
    }
    */
/**
     * 宅基地流转 列表
     *//*

    @RequestMapping(value = "/info", method = RequestMethod.POST)
    public R info(@RequestBody Map map){
        Integer id = null;
        if (map.containsKey("id") && map.get("id") != null){
            id = Integer.valueOf(map.get("id").toString());
        }
        if(id==null){
            return R.error("网络错误");
        }
        Integer[] ids = {id};
        List<ZjdLzEntity> zjdLzEntityList = zjdLzService.queryListById(ids);
        return R.ok().put("data",zjdLzEntityList.get(0));
    }

    */
/*
 * 图表情况
 * *//*

    @RequestMapping("/queryTypeCount")
    public R queryTypeCount(@RequestBody Map map){
        String xzqmc = null;
        if (map.containsKey("xzqmc") && map.get("xzqmc") != null){
            xzqmc = map.get("xzqmc").toString();
        }
        Integer type = null;
        if (map.containsKey("type") && map.get("type") != null){
            type = Integer.valueOf(map.get("type").toString());
        }
        List<ZjdLzEntity> zjdLzEntities = zjdLzService.queryTypeCount(xzqmc,type);
        return R.ok().put("data",zjdLzEntities);
    }

    */
/**
     * 宅基地流转添加申请
     *//*

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public R save(@RequestBody ZjdLzEntity zjdLzEntity){
        if(zjdLzEntity.getZjdFileIds()==null){
            return R.error("资料不全，请补全资料！");
        }
        List<Integer> zjdFileIds = zjdLzEntity.getZjdFileIds();
        //判断申请资料是否完整
        boolean isTrue = zjdLzService.queryFileStatus(1,zjdFileIds);
        if(!isTrue){
            return R.error("资料不全，请补全资料！");
        }
        if(zjdLzEntity.getRemark()!=null){
            zjdLzEntity.setRemark("申请备注："+zjdLzEntity.getRemark()+"\r\n");
        }
        zjdLzService.save(zjdLzEntity);
        //偏亮修改图片表中 流转外键
        zjdFileService.updateZjdId(zjdLzEntity.getId(),zjdFileIds);
        //修改院落
        zjdLzService.updateYl(zjdLzEntity.getYlId(),1);
        return R.ok();
    }

    */
/**
     * next
     *//*

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public R update(@RequestBody ZjdLzEntity zjdLzEntity) {
        if(zjdLzEntity==null){
            return  R.error("网络错误");
        }
        ZjdLzEntity zjdlz = zjdLzService.queryObject(zjdLzEntity.getId());
        if(zjdLzEntity.getRemark()!=null){
            zjdLzEntity.setRemark(zjdlz.getRemark()+ zjdLzEntity.getSptypeText() + "备注："+zjdLzEntity.getRemark()+"\\r\\n");
        }
        if(zjdlz!=null && zjdLzEntity.getSptype()!=null && zjdlz.getSptype()!=null && zjdlz.getSptype()!=zjdLzEntity.getSptype()){
            List<Integer> zjdFileIds = zjdLzEntity.getZjdFileIds();
            //判断申请资料是否完整
            boolean isTrue = zjdLzService.queryFileStatus(zjdLzEntity.getSptype(), new ArrayList<>());
            if(!isTrue){
                return R.error("资料不全，请补全资料！");
            }
        }else if (zjdLzEntity.getSptype() == 5){
            zjdLzEntity.setBhDate(new Date());
            zjdLzService.update(zjdLzEntity);
            zjdLzService.updateYl(zjdlz.getYlId(),zjdLzEntity.getSptype());
        }
        zjdLzService.update(zjdLzEntity);
        zjdLzService.updateYl(zjdlz.getYlId(),zjdLzEntity.getSptype());
        return R.ok();
    }

    */
/**
     * 上传图片
     *//*

    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    public R uploadFile(HttpServletRequest request) throws FileNotFoundException {
        Map<String, Object> map = new HashMap();
        //资料表实体
        List<ZjdFileEntity> zjdFileEntityList = new ArrayList<>();
        ZjdFileEntity zjdFileEntity=new ZjdFileEntity();
        // 获取根目录的绝对路径
        File genPath=new File(ResourceUtils.getURL("classpath:").getPath());
        if(!genPath.exists()){
            genPath=new File("");
        }
        //在开发测试模式时，得到地址为：{项目跟目录}/target/progress/
        //在打成jar正式发布时，得到的地址为:{发布jar包目录}/progress/
        File savePath=new File(genPath.getAbsolutePath(),"fileupload"+ File.separator+SAVE_PATH);
        File savePath1=new File(genPath.getAbsolutePath(),"fileupload");
        if(!savePath.exists()){
            savePath.mkdirs();
            System.out.println("文件路径为：+"+savePath.getAbsolutePath());
        }
        //if (multipartResolver.isMultipart(request)) {
        //转换成多部分request
        MultipartHttpServletRequest multiRequest =null;
        if (request instanceof MultipartHttpServletRequest) {
            multiRequest = (MultipartHttpServletRequest)(request);
        }else {
            return R.error("文件不能为空！");
        }
        String status = multiRequest.getParameter("status");//流程状态
        String key=multiRequest.getParameter("key");//文件类型
        String remark=multiRequest.getParameter("remark");//备注
        Integer zjdId = null;
        if (multiRequest.getParameter("zjdId") != null){
            zjdId = Integer.parseInt(multiRequest.getParameter("zjdId"));
        }
        Integer status1 = Integer.parseInt(status);
        Integer key1 = Integer.parseInt(key);
        //取得request中的所有文件名
        Iterator<String> iter = multiRequest.getFileNames();
        while (iter.hasNext()) {
            //取得上传文件
            MultipartFile file = multiRequest.getFile(iter.next());
            if (file != null) {
                //取得当前上传文件的文件名称
                String myFileName = file.getOriginalFilename();
                //如果名称不为“”,说明该文件存在，否则说明该文件不存在
                if (!"".equals(myFileName.trim())) {
                    //重命名上传后的文件名
                    String fileName = file.getOriginalFilename();
                    //System.out.println(savePath + "\\" + fileName);
                    zjdFileEntity.setFilename(fileName);
                    String ext = fileName.substring(fileName.indexOf("."));
                    TimeString st = new TimeString();
                    zjdFileEntity.setPath(SAVE_PATH+ File.separator+st.getTimeString() + ext);
                    if(remark!=null && !"".equals(remark)){
                        zjdFileEntity.setRemark(remark);
                    }
                    if(zjdId!=null && !"".equals(zjdId)){
                        zjdFileEntity.setZjdId(zjdId);
                    }
                    zjdFileEntity.setKey(key1);
                    zjdFileEntity.setStatus(status1);
                    zjdFileEntity.setUpdate(new Date());
                    zjdFileEntity.setType(2);
                    zjdFileEntityList.add(zjdFileEntity);
                    //上传路径
                    String path = savePath1 + File.separator + zjdFileEntity.getPath();
                    File localFile = new File(path);
                    try {
                        file.transferTo(localFile);
                    } catch (IOException e) {
                        return R.error("上传失败").put("code", 500);
                    }
                }
            } else {
                return R.error("文件不能为空！");
            }
        }
        //}
        List<ZjdFileEntity> zjdFileIds= zjdFileService.saveFileBatch(zjdFileEntityList);
        return R.ok().put("data",zjdFileIds);
    }

    @RequestMapping(value = "/delete")
    public R delete(@RequestBody Map map, HttpServletRequest request) throws FileNotFoundException{
        File genPath=new File(ResourceUtils.getURL("jar:").getPath());
        File savePath=new File(genPath.getAbsolutePath().replace("jar:","fileupload"));
        Integer[] ids = null;
        if (map.containsKey("ids") && map.get("ids") != null){
            String codes  = map.get("ids").toString();
            ArrayList list = new ArrayList(Arrays.asList(codes.split(",")));
            ids = Arrays.stream(list.toArray(new String[list.size()])).map(p ->
                    Integer.valueOf(p.toString())).toArray(Integer[]::new);
        }
       List<ZjdLzEntity> zjdLzEntityList = zjdLzService.queryListById(ids);
        if(zjdLzEntityList!=null && zjdLzEntityList.size()>0){
            for (ZjdLzEntity zjdlz:zjdLzEntityList) {
                if(zjdlz.getZjdFileEntities()!=null){
                    for (ZjdFileEntity zjdFile:zjdlz.getZjdFileEntities()) {
                        File file=new File(savePath + File.separator + zjdFile.getPath());
                        if(file.exists()){
                            file.delete();
                        }
                    }
                }
            }

            zjdLzService.updateYlBatch(ids,0);
            zjdLzService.deleteBatch(ids);
        }
        return R.ok();

    }

    @RequestMapping(value = "/deleteFile")
    public R deleteFile(@RequestBody Map map, HttpServletRequest request) throws FileNotFoundException{
        File genPath=new File(ResourceUtils.getURL("jar:").getPath());
        File savePath=new File(genPath.getAbsolutePath().replace("jar:","fileupload"));
        Integer[] ids = null;
        if (map.containsKey("ids") && map.get("ids") != null){
            String codes  = map.get("ids").toString();
            ArrayList list = new ArrayList(Arrays.asList(codes.split(",")));
            ids = Arrays.stream(list.toArray(new String[list.size()])).map(p ->
                    Integer.valueOf(p.toString())).toArray(Integer[]::new);
        }
        List<ZjdFileEntity> zjdFileEntityList =zjdFileService.queryFileList(ids);
        if(zjdFileEntityList==null){
            return R.ok();
        }
        for (ZjdFileEntity zjdFile:zjdFileEntityList) {
            File file=new File(savePath + File.separator + zjdFile.getPath());
            if(file.exists()){
                file.delete();
            }
        }

        zjdFileService.deleteFileBatch(ids);
        return  R.ok("删除成功");
    }

}
*/
